package com.example.zhanglinqianhui

import Student
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

class AddStudentActivity : AppCompatActivity() {
    private lateinit var studentIdInput: EditText
    private lateinit var nameInput: EditText
    private lateinit var genderInput: EditText
    private lateinit var classInput: EditText

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_student)

        studentIdInput = findViewById(R.id.studentIdInput)
        nameInput = findViewById(R.id.nameInput)
        genderInput = findViewById(R.id.genderInput)
        classInput = findViewById(R.id.classInput)

        val confirmButton: Button = findViewById(R.id.confirmButton)
        val cancelButton: Button = findViewById(R.id.cancelButton)

        confirmButton.setOnClickListener {
            val studentId = studentIdInput.text.toString()
            val name = nameInput.text.toString()
            val gender = genderInput.text.toString()
            val className = classInput.text.toString()

            val newStudent = Student(studentId, name, gender, className)
            val resultIntent = Intent().apply {
                putExtra("student", newStudent)
            }
            setResult(RESULT_OK, resultIntent)
            finish()
        }

        cancelButton.setOnClickListener { finish() }
    }
}
